package sqlmanager;

public class FieldInfo {
	public static final int FieldsCount = 5;

	public String name = "";
	public String type = "";
	public int precision = -1;
	public int scale = -1;
	public boolean notNull = false;
	public boolean autoIncrement = false;
	public boolean primaryKey = false;

	public FieldInfo() {
	}

	public FieldInfo(String name, String type, int precision, int scale, boolean notNull, boolean isAutoIncrement) {
		this.name = name;
		this.type = type;
		this.precision = precision;
		this.scale = scale;
		this.notNull = notNull;
		this.autoIncrement = isAutoIncrement;
	}

	public boolean equals(Object o) {
		if (null == o)
			return false;
		else if (o == this)
			return true;
		else if (false == super.equals(o))
			return false;
		else if (false == o.getClass().equals(this.getClass()))
			return false;

		FieldInfo obj = (FieldInfo) o;
		if (obj.precision == this.precision && obj.scale == this.scale && obj.notNull == this.notNull && obj.autoIncrement == this.autoIncrement
				&& obj.primaryKey == this.primaryKey && obj.name.equals(this.name) && obj.type.equals(this.type))
			return true;
		else
			return false;
	}

	public Object getField(int index) {
		switch (index) {
		case 0:
			return this.name;
		case 1:
			return this.getType();
		case 2:
			return Boolean.valueOf(this.notNull);
		case 3:
			return Boolean.valueOf(this.autoIncrement);
		case 4:
			return Boolean.valueOf(this.primaryKey);
		default:
			return "";
		}
	}

	public String getType() {
		StringBuffer buf = new StringBuffer(type);
		if (this.precision > 0) {
			buf.append("(" + this.precision);
			if (this.scale > 0)
				buf.append(", " + this.scale);
			buf.append(")");
		}
		return buf.toString();
	}
}
